package cn.hjh.service;

import java.util.List;

import cn.hjh.dao.DeptDao;
import cn.hjh.pojo.Dept;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;


public class DeptBiz {
	private DeptDao dao = new DeptDao();
	
	public List<Dept> findProjections_3() {
		Transaction tx = null;
		List<Dept> result = null;
		try {
			
			tx = dao.currentSession().beginTransaction();
			
			result = dao.findByProjection_3();
			
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			if (tx != null)
				tx.rollback();
		}
		return result;
	}
	
	public List<Object[]> findProjections_2() {
		Transaction tx = null;
		List<Object[]> result = null;
		try {
			
			tx = dao.currentSession().beginTransaction();
			
			result = dao.findByProjection_2();
			
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			if (tx != null)
				tx.rollback();
		}
		return result;
	}
	
	public List<String> findProjections() {
		Transaction tx = null;
		List<String> result = null;
		try {
			
			tx = dao.currentSession().beginTransaction();
			
			result = dao.findByProjection();
			
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			if (tx != null)
				tx.rollback();
		}
		return result;
	}
	
	public List<Dept> findDeptByName_2(String deptName) {
		Transaction tx = null;
		List<Dept> result = null;
		try {
			tx = dao.currentSession().beginTransaction();
			result = dao.findDeptByName_2(deptName);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			if (tx != null)
				tx.rollback();
		}
		return result;
	}
	
	public List<Dept> findDeptByName(String deptName) {
		Transaction tx = null;
		List<Dept> result = null;
		try {
			tx = dao.currentSession().beginTransaction();
			result = dao.findDeptByName(deptName);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			if (tx != null)
				tx.rollback();
		}
		return result;
	}
}
